package org.vectrics.user;

import java.util.Comparator;
import org.apache.log4j.Logger;


public class PersonNameComparator implements Comparator {
	private transient Logger log = Logger.getLogger(PersonNameComparator.class);
	
	/**
	 * 
	 */
	public PersonNameComparator() {
		super();
		
	}

	
	public int compare(Object o1, Object o2) {
		log.debug("compare() called");
		int result = 0;

		try {
			Person p1 = (Person)o1;
			Person p2 = (Person)o2;
			log.debug("compare() - comparing user");
			String userName1 = "";
			if (p1 != null)
				userName1 = p1.getLastName() + ", " + p1.getFirstName() + p1.getMiddleName() + p1.getId();
			String userName2 = "";
			if (p2 != null)
				userName2 = p2.getLastName() + ", " + p2.getFirstName() + p2.getMiddleName() + p2.getId();
			result = userName1.compareTo(userName2);
		}
		catch (Exception ex) {
			log.error("Exception comparing users", ex);
		}
		log.debug("compare() finished");
		
		return result;
	}

}
